package cn.virens.packet.factory;

import com.alibaba.fastjson.JSONObject;

import cn.virens.common.ByteUtil;

public class LigthOnPacketFactory extends AbstractFactory {
	private static final int WHOLE = 0; // 全夜灯
	private static final int MIDNIGHT = 1; // 半夜灯
	private static final byte[] ALL_DATA = ByteUtil.toByte("050000000000");
	private static final byte[] WHOLE_DATA = ByteUtil.toByte("060000000000");
	private static final byte[] MIDNIGHT_DATA = ByteUtil.toByte("070000000000");

	@Override
	protected String cmd(JSONObject json) {
		return "23";
	}

	@Override
	protected byte[] data(JSONObject json) {
		if (json != null && type(json.getInteger("type")) == MIDNIGHT) {
			return MIDNIGHT_DATA;
		} else if (json != null && type(json.getInteger("type")) == WHOLE) {
			return WHOLE_DATA;
		} else {
			return ALL_DATA;
		}
	}

	private static int type(Integer type) {
		return type == null ? -1 : type.intValue();
	}

	@Override
	protected String model(JSONObject json) {
		if (json != null && json.containsKey("model")) {
			int model = json.getIntValue("model");

			if (model == 1) { return "01"; }
			if (model == 2) { return "02"; }
		}

		return "00";
	}
}
